package cn.matrix42.potoo.jdbc.connection;

import cn.matrix42.potoo.jdbc.dialect.Dialect;
import cn.matrix42.potoo.jdbc.dialect.DialectFactory;
import cn.matrix42.potoo.jdbc.dialect.DialectFactoryLoader;

import java.sql.SQLException;

public class ConnectionAgentFactory {

    public static ConnectionAgent getConnectionAgent(ConnectionInfo connectionInfo) throws SQLException {
        DialectFactory dialectFactory = DialectFactoryLoader.load(connectionInfo.getUrl());
        Dialect dialect = dialectFactory.create();
        try {
            Class.forName(dialect.getDriver());
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Driver not found:" + dialect.getDriver());
        }
        return new ConnectionAgent(connectionInfo, dialect);
    }

}
